import requests
import re
import urllib.parse

url="http://192.168.1.1"
url1='http://192.168.1.1/getpage.gch?pid=1002&nextpage=status_lan_host_info_BJ_t.gch'

headers={"User-Agent":"Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.108 Safari/537.36","Cookie" : "_TESTCOOKIESUPPORT=1"}

r=requests.get(url)
#print(r.text)

#result=re.search(r'document.getElementById\("Frm_Logintoken"\).value = "(.*)";',r.text)

#print(result.groups()[0])

r1=r'document.getElementById\("Frm_Logintoken"\).value = "(.*)";'
r2=r'document.getElementById\("Frm_Loginchecktoken"\).value = (\d+);'


def postdata(ck,source):
	jk=re.search(ck,source)
	return jk.groups()[0]


#print(postdata(r2,r.text))


# hh="Frm_Logintoken=" +postdata(r1,r.text) + "&Frm_Loginchecktoken=" + postdata(r2,r.text) + "&_cu_url=0&Right=2&Username=&UserRandomNum=95670920&Password=0b1c0803d1299bcc3f6d4bd997adef8c76a2f234f21fb9cb812d884f1568e88f&action=login";
# print(hh)

hh={"Frm_Logintoken":postdata(r1,r.text),"Frm_Loginchecktoken":postdata(r2,r.text),"_cu_url":0,"Right":2,"Username":'',"UserRandomNum":95670920,"Password":"0b1c0803d1299bcc3f6d4bd997adef8c76a2f234f21fb9cb812d884f1568e88f","action":"login"}


#cookies = dict(_TESTCOOKIESUPPORT=1)

#print(hh)
#print(urllib.parse.urlencode(hh))

#urllib.parse.urlencode(hh)

#response = requests.post(url, data = hh,cookies=cookies)

#print(response.text)

#response = requests.post(url, data = hh,headers=headers)

#print(response.cookies.get_dict())

def getCook(url,hh,headers):
	res=requests.post(url, data = hh,headers=headers)
	uu=res.cookies.get_dict()
	del uu['_TESTCOOKIESUPPORT']
	return uu

#print(getCook(url,hh,headers))

ret=requests.get(url1,cookies=getCook(url,hh,headers))
#print(ret.text)

r3=r"Transfer_meaning\('HostName\d+','(.*)'\);"
r4=r"Transfer_meaning\('IPAddress\d+','(.*)'\);"
r5=r"Transfer_meaning\('MACAddress\d+','(.*)'\);"

r6=r"\\x\d[a-z]"

def gettt(rr,source):
	return re.findall(rr,source)

#print(gettt(r3,ret.text))
#print(gettt(r4,ret.text))
#print(gettt(r5,ret.text))


#print(re.search(r6,'192\\x2e168\\x2e1\\x2e13'))

#ii=re.findall(r6,'192\\x2e168\\x2e1\\x2e13')
#print(ii)

def gang(rr,ll):
	oo=[]
	for i in ll:
	    oo.append(re.sub(rr,'-',i))
	return oo
	   
	



print(gang(r6,gettt(r3,ret.text)))

print(gang(r6,gettt(r4,ret.text)))
print(gang(r6,gettt(r5,ret.text)))

#print(gang(r6,gettt(r3,ret.text)))




'''
ss='192\\x2e168\\x2e1\\x2e13'

if '\\x2e' in ss:
	uu=ss.replace('\\x2e','-')
print(uu)	

'''